package com.horoscope.astrology.zodiac.signs.free.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.horoscope.astrology.zodiac.signs.free.dao.Quote
import com.horoscope.astrology.zodiac.signs.free.dao.QuoteDao

/**
 *  作者    1024
 *  时间    2020/4/26 上午9:31
 *  文件    项目备份
 *  描述    获取数据库对象
 */
@Database(entities = [Quote::class], version = 1, exportSchema = false)
abstract class QuoteDB : RoomDatabase() {
    abstract fun quoteDao(): QuoteDao

    companion object {
        private var instance: QuoteDB? = null

        @Synchronized
        fun get(context: Context): QuoteDB {
            if (instance == null) {
                instance = Room.databaseBuilder(
                    context.applicationContext,
                    QuoteDB::class.java, "MyQuote"
                ).createFromAsset("database/quote.db")
                    .build()
            }
            return instance!!
        }
    }
}